package hello;

public class Pratice4 {
	public static void main(String[] args) {
		/*
		 * int sum=s(100); System.out.println(sum); }
		 * 
		 * public static int s(int i) { if(i==1) return 1; else return i+s(i-1);
		 * int a[]=new int[10]; Scanner in=new Scanner(System.in); for(int
		 * i=0;i<=9;i++){ a[i]=in.nextInt(); int sum=sum+a[i]; int j,k;
		 * if(a[i]>0) j++; else k++; } System.out.println("平均值为："+sum/10);
		 * System.out.println("正数有 "+j+"个"); System.out.println("负数有"+k+"个");
		 */

		/*int a[][] = { { 1, 2, 3 ,10}, { 4, 5, 6,11 }, { 7, 8, 9,12 },{13,14,15,16} };
		out(a);
		System.out.println();
		int c;
		for (int i = 0; i < a.length;i++) {
			for (int j = i+1; j <a[i].length; j++) {
				c = a[i][j];
				a[i][j] = a[j][i];
				a[j][i] = c;
			}
		}

		out(a);
		

	}*/
		
		int a[][]=new int[6][];
		for(int i=0;i<a.length;i++){
		    a[i]=new int[i+1];//第几行分配几个空间
			a[i][0]=1;
			a[i][i]=1;
		}
		out(a);
			for(int i=2;i<a.length;i++){
				for(int j=1;j<i;j++){//j<i下三角
					a[i][j]=a[i-1][j-1]+a[i-1][j];
				}
			}
		out(a);
	}

	private static void out(int[][] a) {
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.print(a[i][j]+" ");
			}System.out.println();
		}
	}
}
